//! 本地全功能节点
//!

use crate::bean::node::base_node::BaseNode;
use std::ops::{Deref, DerefMut};

#[derive(Debug, Clone, Default)]
pub struct LocalFullNode {
    base_node: BaseNode, // 基本节点
    hash: String,        // 对应区块的hash值(变更节点信息回更新)
    shard: String,       // 节点所属分片ID
    index: String,       // 节点在所属分片内的索引
}

impl LocalFullNode {
    pub fn new(base_node: &BaseNode, hash: &str, shard: &str, index: &str) -> Self {
        Self {
            base_node: base_node.clone(),
            hash: hash.to_string(),
            shard: shard.to_string(),
            index: index.to_string(),
        }
    }

    pub fn base_node(&self) -> &BaseNode {
        &self.base_node
    }

    pub fn hash(&self) -> &str {
        &self.hash
    }

    pub fn shard(&self) -> &str {
        &self.shard
    }

    pub fn index(&self) -> &str {
        &self.index
    }

    pub fn set_base_node(&mut self, base_node: &BaseNode) {
        self.base_node = base_node.clone();
    }

    pub fn set_hash(&mut self, hash: &str) {
        self.hash = hash.to_string();
    }

    pub fn set_shard(&mut self, shard: &str) {
        self.shard = shard.to_string();
    }

    pub fn set_index(&mut self, index: &str) {
        self.index = index.to_string();
    }
}

impl Deref for LocalFullNode {
    type Target = BaseNode;

    fn deref(&self) -> &Self::Target {
        &self.base_node
    }
}

impl DerefMut for LocalFullNode {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.base_node
    }
}
